package com.api.user.controller;

import com.api.core.annotation.PowerEnable;
import com.api.core.config.AuthUser;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.service.UserImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;



/**
* Created by wanghuiwen on 2021/04/14.
*/
@PowerEnable(name = "user_image",url = "/user/image")
@Api(value = "user_image", tags = {"user_image"})
@RestController
@RequestMapping("/user/image")
public class UserImageController extends Ctrl{
    @Resource
    private UserImageService userImageService;

    @ApiOperation(value = "user_image添加", tags = {"user_image"}, notes = "user_image添加")
    @PostMapping(value="/add",name="user_image添加")
    public Result add(HttpServletRequest request, Authentication authentication) {
        AuthUser authUser = getAuthUser(authentication);
       return userImageService.add(request,authUser);
    }

    @ApiOperation(value = "user_image删除", tags = {"user_image"}, notes = "user_image删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "user_imageid", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/delete",name="user_image删除")
    public Result delete(@RequestParam Long id) {
        userImageService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "user_image列表信息", tags = {"user_image"}, notes = "user_image列表信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "search", value = "查询条件json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "order", value = "排序json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/list/user", name = "user_image列表信息")
    public Result list(Authentication authentication) {
        AuthUser authUser = getAuthUser(authentication);
        return userImageService.listUser(authUser.getId());
    }
}
